#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mini=0x3f3f3f3f;
    for(char ch='a';ch<='z';ch++)
    {
        int sum=0;
        for(auto& e:s)
        {
            if(e<ch)
            {
                sum+=min(ch-e,'z'-ch+1+e-'a');
            }
            else
            {
                sum+=min(e-ch,'z'-e+1+ch-'a');
            }
            
        }
        mini=min(mini,sum);
    }
    cout<<mini;
    return 0;
}